<?php
    require_once 'config.php';
?>
<?php 
    /* 注册页简单添加用户信息 
     * @param uName email uPass
     * @return  Primary_key_id
     * */

    function addRegUser($uName,$email,$uPass)
    {
        $db=getConnect();
        $sqlAdd="INSERT INTO User(uId,uName,email,uPass,head,sex,birthday,book,movie,statement,regtime,money)
                 VALUES ('','$uName','$email','$uPass','0.png','保密',NULL,NULL,NULL,NULL,now(),'0')";
        $result=add($sqlAdd);
        return $result;
    }
    
    /* 查找用户信息 根据用户姓名或邮箱
     * @param noe 用户名或邮箱
     * @return array
     *  */
    function getUserNameEmail($noe)//条件判断
    {
        
        $sqlGet="SELECT * FROM User WHERE uName='$noe' union SELECT * FROM User WHERE email='$noe'";
        $result=getQuery($sqlGet);
        if (count($result)>0) 
        {
            return $result[0];
        }
        return $result; //返回数组
    }
    
    /* 根据用户名查找用户信息
     * @param uName 传递参数uName
     * @return array
     *  */
    function getUserName($uName) {
        $sqlGet="SELECT * FROM User WHERE uName='$uName'";
        $result=getQuery($sqlGet);
        if (count($result)>0) 
        {
            return $result[0];
        }
        return $result;
    }
    
    /*根据用户Id查找用户信息
     * @param uId 传递参数uId
     * @return array
     *   */
    
    function getUserId($uId){
        $sqlGet="SELECT * FROM User WHERE uId='$uId'";
        $result=getQuery($sqlGet);
        if (count($result)>0)
        {
            return $result[0];
        }
        return $result;
    }
    
    /* 根据用户Id更改用户密码
     * @param uId 条件
     * @param uPass 更改结果
     * @return rows-matched
     *  */
    function updatePass($uId,$uPass){
        $sqlUp="UPDATE User SET uPass='$uPass' WHERE uId='$uId'";
        $result=update($sqlUp);
    }
    
    /* 更换用户头像
     * @param $head 更新内容
     * @param $uId 判断参数
     * @return 操作行
     * */
    function updatehead($uId,$head){
        $sqlUp="UPDATE User SET head='$head' WHERE uId='$uId' ";
        $result=update($sqlUp);
    }
    
    /* 更新用户信息，不更新注册时间，头像，用户Id 
     * @param 用户信息
     * @param uId 判断更新条件
     * @return rows-matched（操作行）
     * */
    function updateUser($uId,$uName,$email,$uPass,$sex,$birthday,$book,$movie,$statement){
        $sqlUp="UPDATE User SET uName='$uName', email='$email', uPass='$uPass', sex='$sex', birthday='$birthday', book='$book',movie='$movie', statement='$statement' WHERE uId='$uId' ";
        $result=update($sqlUp);
        return $result;
        
    }
    
    /*根据用户id，得到用户邮箱 
     * @param uId
     * @return array
     *  */
    function getEmail($uId){
        $sqlGet="SELECT email FROM User WHERE uId='$uId'";
        $result=getQuery($sqlGet);
        if (count($result)>0)
        {
            return $result[0];
        }
        return $result;
    }
    
    /* 根据用户id添加用户金币
     * @param uId
     * return row
     *  */
    function updateMoney($uId){
        $sqlUp="UPDATE User SET money= money+5 WHERE uId='$uId'";
        $result=update($sqlUp);
        return $result;
    }
    
    //根据用户编号查询用户名字
    function  getusernameUId($uId)
    {
        $sqlGet="select uname from User,review where user.uId=review.uId and review.uId=$uId";
        $result=getQuery($sqlGet);
        if (count($result)>0)
        {
            return $result[0];
        }
        return $result;
    }
    
    
    /* 根据用户id删除用户金币
     * @param uId
     * return row
     *  */
    function exchangeMoney($uId){
        $sqlUp="UPDATE User SET money= money-10 WHERE uId='$uId'";
        $result=update($sqlUp);
        return $result;
    }
    
    /*根据用户id，得到用户金币
     * @param uId
     * @return array
     *  */
    function getMoney($uId){
        $sqlGet="SELECT money FROM User WHERE uId='$uId'";
        $result=getQuery($sqlGet);
        if (count($result)>0)
        {
            return $result[0];
        }
        return $result;
    }
    
?>